import Vue from 'vue'
import App from './App'
import store from './store' // store
import plugins from './plugins' // plugins
import './permission' // permission
// import Vant from './node_modules/vant/lib/vant'
// import GoEasy from "./node_modules/goeasy/goeasy.min.js";
import GoEasy from '@/api/goeasy-2.5.13.min';
import uView from "uview-ui";
// const goEasy = GoEasy.getInstance({
// 	host: "hangzhou.goeasy.io", //应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
// 	appkey: "BC-93c92f787aa54f5890af55ada5e8a059", // common key,
// 	modules: ['im']
// });
Vue.use(plugins)
// Vue.use(Vant)
// main.js

Vue.use(uView);

// Vue.prototype.goEasy = goEasy;
Vue.config.productionTip = false
Vue.prototype.$store = store

App.mpType = 'app'

const app = new Vue({
	...App
})

app.$mount()
const goEasy = GoEasy.getInstance({
	host: "hangzhou.goeasy.io", //应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
	appkey: "BC-93c92f787aa54f5890af55ada5e8a059", // common key,
	modules: ['im'],
	// true表示支持通知栏提醒，false则表示不需要通知栏提醒
	allowNotification: true //仅有效于app,小程序和H5将会被自动忽略
});

goEasy.im.on(GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, setUnreadNumber);

function setUnreadNumber(content) {
	let unreadTotal = content.unreadTotal;
	if (unreadTotal > 0) {
		uni.setTabBarBadge({
			index: 2,
			text: unreadTotal.toString()
		});
	} else {
		// removeTabBarBadge
		uni.hideTabBarRedDot({
			index: 2
		});
	}
}

goEasy.onClickNotification((message) => {
	let currentUrl;
	const routes = getCurrentPages();

	if (routes && routes.length) {
		const curRoute = routes[routes.length - 1].route;
		const curParam = routes[routes.length - 1].options;
		currentUrl = '/' + curRoute + `?to=${curParam.to}`;
	}

	let newUrl;
	switch (message.toType) {
		case GoEasy.IM_SCENE.PRIVATE:
			newUrl = '/pages/privateChat?to=' + message.senderId;
			break;
		case GoEasy.IM_SCENE.GROUP:
			newUrl = '/pages/groupChat?to=' + message.groupId;
			break;
	}

	if (currentUrl !== newUrl) {
		uni.navigateTo({
			url: newUrl,
		});
	}

});

Vue.prototype.GoEasy = GoEasy;
Vue.prototype.goEasy = goEasy;
